var merge = function(intervals) {
    intervals.sort((a, b) => {
        if (a[0] > b[0]) {
            return 1
        } else {
            return -1
        }
    })
    console.log(intervals)
    let rsl = [intervals[0]]
    for (let i = 1; i < intervals.length; i++) {
        const item = intervals[i]
        let current = rsl[rsl.length - 1]
        if (item[0] <= current[1]) {
            rsl.pop()
            rsl.push([current[0], Math.max(item[1], current[1])])
        } else {
            rsl.push(item)
        }
    }
    return rsl
};
console.log(merge([
    [1, 4],
    [2, 3]
]))